package org.rsbot.script.methods;

import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSItem;

public class Equipment extends MethodProvider
{
  public static final int ITEM_SLOTS = 11;
  public static final int INTERFACE_EQUIPMENT = 387;
  public static final int HELMET = 8;
  public static final int CAPE = 11;
  public static final int NECK = 14;
  public static final int WEAPON = 17;
  public static final int BODY = 20;
  public static final int SHIELD = 23;
  public static final int LEGS = 26;
  public static final int HANDS = 29;
  public static final int FEET = 32;
  public static final int RING = 35;
  public static final int AMMO = 38;

  Equipment(MethodContext paramMethodContext)
  {
    super(paramMethodContext);
  }

  public RSInterface getInterface()
  {
    if (this.methods.game.getCurrentTab() != 5) {
      if (this.methods.bank.isOpen()) {
        this.methods.bank.close();
      }
      this.methods.game.openTab(5);
      sleep(random(900, 1500));
    }
    return this.methods.interfaces.get(387);
  }

  public RSItem[] getItems()
  {
    RSComponent[] arrayOfRSComponent = getInterface().getComponents();
    RSItem[] arrayOfRSItem = new RSItem[11];
    for (int i = 0; i < arrayOfRSItem.length; i++) {
      arrayOfRSItem[i] = new RSItem(this.methods, arrayOfRSComponent[(i * 3 + 8)]);
    }
    return arrayOfRSItem;
  }

  public RSItem[] getCachedItems()
  {
    RSInterface localRSInterface = this.methods.interfaces.get(387);
    RSComponent[] arrayOfRSComponent = localRSInterface.getComponents();
    RSItem[] arrayOfRSItem = new RSItem[11];
    for (int i = 0; i < arrayOfRSItem.length; i++) {
      arrayOfRSItem[i] = new RSItem(this.methods, arrayOfRSComponent[(i * 3 + 8)]);
    }
    return arrayOfRSItem;
  }

  public RSItem getItem(int paramInt)
  {
    return new RSItem(this.methods, getInterface().getComponents()[paramInt]);
  }

  public int getCount()
  {
    return 11 - getCount(-1);
  }

  public int getCount(int paramInt)
  {
    int i = 0;
    for (RSItem localRSItem : getItems()) {
      if (localRSItem.getID() == paramInt) {
        i++;
      }
    }
    return i;
  }

  public boolean containsAll(int[] paramArrayOfInt)
  {
    RSItem[] arrayOfRSItem1 = getItems();
    int i = 0;
    for (int m : paramArrayOfInt) {
      for (RSItem localRSItem : arrayOfRSItem1) {
        if (localRSItem.getID() == m) {
          i++;
          break;
        }
      }
    }
    return i == paramArrayOfInt.length;
  }

  public boolean containsOneOf(int[] paramArrayOfInt)
  {
    for (RSItem localRSItem : getItems()) {
      for (int n : paramArrayOfInt) {
        if (localRSItem.getID() == n)
          return true;
      }
    }
    return false;
  }
}